<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::get('/user', function (Request $request) {
    return $request->user();
})->middleware('auth:sanctum');


Route::prefix('/v1')
    ->group(function () {
        Route::post('auth/login', [\App\Http\Controllers\AuthController::class, 'login']);
        Route::get('auth/captcha', function () {
            return ['code' => 20200, 'msg' => '操作完成', 'data' => \Mews\Captcha\Facades\Captcha::create(api: true)];
        });


        Route::middleware(\App\Http\Middleware\AuthMiddleware::class)->group(function () {
            Route::get('auth/profile', [\App\Http\Controllers\AuthController::class, 'index']);
            Route::put('auth/update-password', [\App\Http\Controllers\AuthController::class, 'updatePwd']);

            Route::get('setting/menu', [\App\Http\Controllers\Setting\MenuController::class, 'index'])
                ->name('菜单列表接口');
            Route::get('setting/menu/{id}', [\App\Http\Controllers\Setting\MenuController::class, 'detail'])
                ->name('菜单详情接口');
            Route::post('setting/menu', [\App\Http\Controllers\Setting\MenuController::class, 'store'])
                ->name('添加菜单接口');
            Route::put('setting/menu/{id}', [\App\Http\Controllers\Setting\MenuController::class, 'update'])
                ->name('修改菜单接口');
            Route::delete('setting/menu', [\App\Http\Controllers\Setting\MenuController::class, 'destroy'])
                ->name('删除菜单接口');

            Route::put('setting/permission/refresh', [\App\Http\Controllers\Setting\PermissionController::class, 'refresh'])
                ->name('刷新接口信息');
            Route::get('setting/permission', [\App\Http\Controllers\Setting\PermissionController::class, 'index'])
                ->name('权限列表接口');
            Route::get('setting/permission/keys', [\App\Http\Controllers\Setting\PermissionController::class, 'getAllPermissionKeys'])
                ->name('权限key列表接口');
            Route::get('setting/permission/{id}', [\App\Http\Controllers\Setting\PermissionController::class, 'detail'])
                ->name('权限详情接口');
            Route::post('setting/permission', [\App\Http\Controllers\Setting\PermissionController::class, 'store'])
                ->name('添加权限接口');
            Route::put('setting/permission/{id}', [\App\Http\Controllers\Setting\PermissionController::class, 'update'])
                ->name('修改菜单接口');
            Route::delete('setting/permission', [\App\Http\Controllers\Setting\PermissionController::class, 'destroy'])
                ->name('删除权限接口');

            Route::get('setting/role', [\App\Http\Controllers\Setting\RoleController::class, 'index'])
                ->name('角色列表接口');
            Route::get('setting/role/options', [\App\Http\Controllers\Setting\RoleController::class, 'options'])
                ->name('角色options列表接口');
            Route::get('setting/role/{id}', [\App\Http\Controllers\Setting\RoleController::class, 'detail'])
                ->name('角色详情接口');
            Route::post('setting/role', [\App\Http\Controllers\Setting\RoleController::class, 'store'])
                ->name('添加角色接口');
            Route::put('setting/role/{id}', [\App\Http\Controllers\Setting\RoleController::class, 'update'])
                ->name('修改角色接口');
            Route::delete('setting/role', [\App\Http\Controllers\Setting\RoleController::class, 'destroy'])
                ->name('删除角色接口');

            Route::get('setting/user', [\App\Http\Controllers\Setting\UserController::class, 'index'])
                ->name('用户列表接口');
            Route::get('setting/user/{id}', [\App\Http\Controllers\Setting\UserController::class, 'detail'])
                ->name('用户详情接口');
            Route::post('setting/user', [\App\Http\Controllers\Setting\UserController::class, 'store'])
                ->name('添加用户接口');
            Route::put('setting/user/reset-password/{id}', [\App\Http\Controllers\Setting\UserController::class, 'resetPwd'])
                ->name('重置用户密码接口');
            Route::put('setting/user/{id}', [\App\Http\Controllers\Setting\UserController::class, 'update'])
                ->name('修改用户接口');
            Route::delete('setting/user', [\App\Http\Controllers\Setting\UserController::class, 'destroy'])
                ->name('删除用户接口');
        });

        Route::group(['prefix' => '/dev'], function () {
            Route::post('/component', [\App\Http\Controllers\DevController::class, 'importVueComponent'])->name('vue组件');
            Route::get('/permission', [\App\Http\Controllers\DevController::class, 'getPermission']);
            Route::post('/permission', [\App\Http\Controllers\DevController::class, 'importPermission']);
        });
    });
